<template>
  <div class="container">
    <div class="box">
      <el-form>
        <el-form-item label="签到时间">
          <el-time-picker v-model="end"></el-time-picker>
        </el-form-item>
        <el-button @click="begin" type="primary">发布签到</el-button>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import axios from "axios";
import { useRoute } from "vue-router";
import { ElMessage } from "element-plus";

const route = useRoute();
const id = route.query.cno;
const end = ref('');
const time_end = new Date();

const begin = () => {
  time_end.setHours(end.value.getHours());
  time_end.setMinutes(end.value.getMinutes());
  time_end.setSeconds(end.value.getSeconds());
  const now = new Date();
  const informVo = {
    title: '签到',
    content: '签到',
    cno: id,
    time_start: now.toISOString(),
    time_end: time_end.toISOString()
  };
  console.log(informVo);
  axios.post('http://localhost:8080/inform', informVo).catch(error => {
    window.alert('有问题' + error);
  });
  ElMessage({
    type: 'success',
    message: "发布成功",
  });
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f7fa;
}

.box {
  width: 300px;
  padding: 24px;
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border: 1px solid #ebeef5;
}

.el-form-item {
  margin-bottom: 16px;
}

.el-button {
  width: 100%;
}
</style>